﻿using System;
using System.Collections.Generic;
 
using System.Text;

namespace GGSharp.Packets
{
    public class MessageAcknowledgePacket : HeaderPacket
    {
        private int _status = 0;
        private int _recipient;
        private int _seq;

        public MessageAcknowledgePacket()
        {
            this.Length = 12;
            this.Type = PacketType.GG_SEND_MSG_ACK;
        }

        public MessageStatus Status
        {
            get { return TranslateMessageStatus(_status); }
            set { _status = (int)value; }
        }

        public int StatusRaw
        {
            get { return _status; }
            set { _status = value; }
        }

        public int Recipient
        {
            get { return _recipient; }
            set { _recipient = value; }
        }

        public int Sequence
        {
            get { return _seq; }
            set { _seq = value; }
        }

        public override void Read(System.IO.BinaryReader reader)
        {
            base.Read(reader);

            _status = reader.ReadInt32();
            _recipient = reader.ReadInt32();
            _seq = reader.ReadInt32();

            this.ReadToEnd(12, reader);
        }

        public override void Write(System.IO.BinaryWriter writer)
        {
            base.Write(writer);
            writer.Write(_status);
            writer.Write(_recipient);
            writer.Write(_seq);
        }

        protected MessageStatus TranslateMessageStatus(int status)
        {
            try
            {
                return (MessageStatus)status;
            }
            catch (Exception e)
            {
                return MessageStatus.Uknown;
            }
        }
    }
}
